//Drawing management

#include <SDL/SDL.h>
#include "out_drawing.h"


void initCouleurs(Uint32 *couleurs, SDL_Surface *ecran){
  couleurs[C_NOIR]          = SDL_MapRGB(ecran->format, 0x00, 0x00, 0x00);
  couleurs[C_BLEU_FONCE]    = SDL_MapRGB(ecran->format, 0x00, 0x00, 0x80);
  couleurs[C_VERT_FONCE]    = SDL_MapRGB(ecran->format, 0x00, 0x80, 0x00);
  couleurs[C_CYAN_FONCE]    = SDL_MapRGB(ecran->format, 0x00, 0x80, 0x80);
  couleurs[C_ROUGE_FONCE]   = SDL_MapRGB(ecran->format, 0x80, 0x00, 0x00);
  couleurs[C_MAGENTA_FONCE] = SDL_MapRGB(ecran->format, 0x80, 0x00, 0x80);
  couleurs[C_OCRE]          = SDL_MapRGB(ecran->format, 0x80, 0x80, 0x00);
  couleurs[C_GRIS_CLAIR]    = SDL_MapRGB(ecran->format, 0xC0, 0xC0, 0xC0);
  couleurs[C_GRIS]          = SDL_MapRGB(ecran->format, 0x80, 0x80, 0x80);
  couleurs[C_BLEU]          = SDL_MapRGB(ecran->format, 0x00, 0x00, 0xFF);
  couleurs[C_VERT]          = SDL_MapRGB(ecran->format, 0x00, 0xFF, 0x00);
  couleurs[C_CYAN]          = SDL_MapRGB(ecran->format, 0x00, 0xFF, 0xFF);
  couleurs[C_ROUGE]         = SDL_MapRGB(ecran->format, 0xFF, 0x00, 0x00);
  couleurs[C_MAGENTA]       = SDL_MapRGB(ecran->format, 0xFF, 0x00, 0xFF);
  couleurs[C_JAUNE]         = SDL_MapRGB(ecran->format, 0xFF, 0xFF, 0x00);
  couleurs[C_BLANC]         = SDL_MapRGB(ecran->format, 0xFF, 0xFF, 0xFF);
}


inline void setPixel(int x, int y, Uint32 coul, SDL_Surface *ecran){	//drawing of a pixel
  *((Uint32*)(ecran->pixels) + x + y * ecran->w) = coul;
}

void rect(int x, int y, int w, int h, Uint32 coul, SDL_Surface *ecran){//draw a rectangle
  SDL_Rect r;

  r.x = x;
  r.y = y;
  r.w = w;
  r.h = h;

  SDL_FillRect(ecran, &r, coul);
}


void clearScr(Uint32 coul, SDL_Surface *ecran){	//clear the screen
	SDL_FillRect(ecran, NULL, coul);
}

void lineHor(int x, int y, int w, Uint32 coul, SDL_Surface *ecran){	//quicker than lineVert.
  SDL_Rect r;

  r.x = x;
  r.y = y;
  r.w = w;
  r.h = 1;

  SDL_FillRect(ecran, &r, coul);
}

void lineVert(int x, int y, int h, Uint32 coul, SDL_Surface *ecran){
  SDL_Rect r;

  r.x = x;
  r.y = y;
  r.w = 1;
  r.h = h;

  SDL_FillRect(ecran, &r, coul);
}


